﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CreateReport();

        }
    }
    /// <summary>
    /// 生成报表数据
    /// </summary>
    private void CreateReport()
    {
        //获取数据源
        DataTable dt = DBBLL.GetStudentInfoList();
        //设置是否允许报表展示图片 默认为false
        //RptView.LocalReport.EnableExternalImages = true;
        //设置报表路径
        RptView.LocalReport.ReportPath = "RDLC\\Report_Student.rdlc";
        //清空报表数据
        RptView.LocalReport.DataSources.Clear();
        //添加报表数据集  数据集的名称为报表控件中的集合名称
        RptView.LocalReport.DataSources.Add(new ReportDataSource("ds_student", dt));
        this.RptView.LocalReport.EnableHyperlinks = true;
        //设置报表参数
        SetReportParameters(this.RptView.LocalReport);
        //绑定报表
        RptView.DataBind();
    }

    /// <summary>
    /// 设置报表参数
    /// </summary>
    private void SetReportParameters(Report localReport)
    {
        //定义报表参数数组
        ReportParameter[] parameters = new ReportParameter[2];
        //参数赋值   参数名称要与报表中的参数名称对应
        parameters[0] = new ReportParameter("author", "cjzhang--张成建");
        parameters[1] = new ReportParameter("time", System.DateTime.Now.ToShortDateString());

      
        localReport.SetParameters(parameters);
    }

    protected void RptView_Drillthrough(object sender, DrillthroughEventArgs e)
    {

        DataTable dt = new DataTable();

        LocalReport localReport = (LocalReport)e.Report;
        //获取从父页面传递过来的参数值
        string userid = localReport.OriginalParametersToDrillthrough[0].Values[0].ToString();
        
        //打开子页面
        string url = "window.open('ScoreInfo.aspx?userid=" + userid + "','930','800');"; 
        ScriptManager.RegisterStartupScript(this, GetType(), "openreport", url, true);
         
        //这个必须设置，不设置父页面也会跳转
        e.Cancel = true;
    }
}
